<template lang="html">
  <div>
    <selfHeader></selfHeader>
    <div class="car">
      <mt-field label="收货人姓名" placeholder="请输入收货人姓名" v-model="from.realName"></mt-field>
      <mt-field label="收货人电话" placeholder="请输入收货人电话" v-model="from.phone"></mt-field>
      <mt-field label="所在省份" placeholder="请输入所在省份" v-model="from.province"></mt-field>
      <mt-field label="所在城市" placeholder="请输入所在城市" v-model="from.city"></mt-field>
      <mt-field label="所在区县" placeholder="请输入所在区县" v-model="from.district"></mt-field>
      <mt-field label="详细地址" placeholder="请输入详细地址" v-model="from.detail"></mt-field>
      <mt-switch v-model="from.isDefault">是否设为默认地址</mt-switch>
      <button class="btn" @click='appAdd'>修改地址</button>
    </div>
  </div>
</template>

<script>
import {appEdit} from '@/http/api'
import selfHeader from '@/common/header'
import Baseline from '@/common/_baseline.vue'
import {Toast, Field, Switch} from 'mint-ui'

export default {
  components: {
    'v-baseline': Baseline,
    Field,
    selfHeader,
    'mt-switch': Switch
  },
  data() {
    return {
      from: {
        realName: '',
        phone: '',
        province: '',
        city: '',
        district: '',
        detail: '',
        isDefault: false
      }
    }
  },
  created() {
    console.log(this.$route.query)
    this.from = this.$route.query.data
  },
  methods: {
    async appAdd() {
      const user = JSON.parse(localStorage.getItem('UserMessage'))
      const data = {
        uid: user.user.uid,
        ...this.from
      }
      const res = await appEdit(data)
      if (res.code * 1 === 200) {
        Toast('地址修改成功');
      }
    }
  }
}
</script>

<style lang="less" scoped>
@import '../assets/fz.less';
@import '../assets/index/style.css';
@import '../assets/user/icon/carstyle.css';
.car {
  margin-top: 60px;
}
</style>
